home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Display Manager SDK / Sample Code / Display Changed CWPro3 / Source / aevt.c next >
Encoding:
C/C++ Source or Header  |  1999-01-20  |  5.1 KB  |  202 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        aevt.c
  4. #
  5. #        Apple events handler.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    marink@apple.com
  9. #
  10. #        Modification History: 
  11. #
  12. #            1/19/99        ewa     update to CWPro3 and universal interfaces                     
  13. #            10/12/95    MWM     Initial coding                     
  14. #
  15. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  16. #
  17. #
  18. #        You may incorporate this sample code into your applications without
  19. #        restriction, though the sample code has been provided "AS IS" and the
  20. #        responsibility for its operation is 100% yours.  However, what you are
  21. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  22. #        after having made changes. If you're going to re-distribute the source,
  23. #        we require that you make it clear in the source that the code was
  24. #        descended from Apple Sample Code, but that you've made changes.
  25. #
  26. *************************************************************************************/
  27.  
  28. #include <AppleEvents.h>
  29. #include <Windows.h>
  30.  
  31. #include "App.h"
  32. #include "Proto.h"
  33.  
  34.  
  35. //----------------------------------------------------------------------
  36. //    Globals
  37. //----------------------------------------------------------------------
  38.  
  39. extern Boolean                gDone;
  40. extern AEEventHandlerUPP    gAEOpenAppUPP;
  41. extern AEEventHandlerUPP    gAEQuitAppUPP;
  42. extern AEEventHandlerUPP    gAEOpenDocUPP;
  43. extern AEEventHandlerUPP    gAEPrintDocUPP;
  44.  
  45.  
  46. //----------------------------------------------------------------------
  47. //
  48. //    AEInit - initialize all the core apple events
  49. //
  50. //
  51. //----------------------------------------------------------------------
  52.  
  53. OSErr AEInit(void)
  54. {    
  55.     OSErr        err = noErr;
  56.                     
  57.     // allocate UPPs
  58.     gAEOpenAppUPP = NewAEEventHandlerProc(DoAEOpenApp);
  59.     gAEQuitAppUPP = NewAEEventHandlerProc(DoAEQuitApp);
  60.     gAEOpenDocUPP = NewAEEventHandlerProc(DoAEOpenDoc);
  61.     gAEPrintDocUPP = NewAEEventHandlerProc(DoAEPrintDoc);
  62.  
  63.     if (nil != gAEOpenAppUPP)        //    install auto Open App
  64.         err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, 
  65.                                     gAEOpenAppUPP, 0L, false );
  66.                                                     
  67.     if (noErr == err && nil != gAEQuitAppUPP)            // install auto Quit App
  68.         err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  69.                                     gAEQuitAppUPP, 0L, false );
  70.         
  71.     if (noErr == err && nil != gAEOpenDocUPP)            // install auto Open Document
  72.         err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
  73.                                     gAEOpenDocUPP, 0L,false);
  74.         
  75.     if (noErr == err && nil != gAEPrintDocUPP)            // install auto Print Document
  76.         err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
  77.                                     gAEPrintDocUPP, 0L,false);
  78.                 
  79.     return err;
  80.                                                 
  81. }
  82.  
  83.  
  84. //----------------------------------------------------------------------
  85. //
  86. //    AEDispose - dispose of UPPs 
  87. //
  88. //
  89. //----------------------------------------------------------------------
  90.  
  91. void AEDispose(void)
  92. {
  93.     if (nil != gAEOpenAppUPP)
  94.         DisposeRoutineDescriptor(gAEOpenAppUPP);
  95.  
  96.     if (nil != gAEQuitAppUPP)
  97.         DisposeRoutineDescriptor(gAEQuitAppUPP);
  98.  
  99.     if (nil != gAEOpenDocUPP)
  100.         DisposeRoutineDescriptor(gAEOpenDocUPP);
  101.  
  102.     if (nil != gAEPrintDocUPP)
  103.         DisposeRoutineDescriptor(gAEPrintDocUPP);
  104.         
  105. }
  106.  
  107.  
  108. //----------------------------------------------------------------------
  109. //
  110. //    DoAEOpenApp - called by the Finder at launch time
  111. //
  112. //
  113. //----------------------------------------------------------------------
  114.  
  115. pascal OSErr DoAEOpenApp(AppleEvent *event, AppleEvent reply, long refCon)
  116. {
  117.     #pragma unused( event, reply, refCon )
  118.  
  119.     return noErr;
  120.         
  121. }
  122.  
  123.  
  124. //----------------------------------------------------------------------
  125. //
  126. //     DoAEQuitApp -    called when the Finder asks app to quit
  127. //
  128. //
  129. //----------------------------------------------------------------------
  130.  
  131. pascal OSErr DoAEQuitApp(AppleEvent *event, AppleEvent reply, long refCon)
  132. {
  133.     #pragma unused( event, reply, refCon )
  134.  
  135.     // set the global quit flag
  136.     gDone = true;
  137.     
  138.     return noErr;
  139.         
  140. }
  141.  
  142.  
  143. //----------------------------------------------------------------------
  144. //
  145. //    DoAEOpenDoc - called when the Finder asks app to open a document
  146. //
  147. //
  148. //----------------------------------------------------------------------
  149.  
  150. pascal OSErr DoAEOpenDoc(AppleEvent *event, AppleEvent reply, long refCon)
  151. {    
  152.     #pragma unused(reply, refCon)
  153.     
  154.  
  155.     return noErr;
  156.  
  157. }
  158.                 
  159.                                         
  160. //----------------------------------------------------------------------
  161. //
  162. //    DoAEPrintDoc - called when the Finder asks app to print a document
  163. //
  164. //
  165. //----------------------------------------------------------------------
  166.  
  167. pascal OSErr DoAEPrintDoc(AppleEvent *event, AppleEvent reply, long refCon)
  168. {
  169.     #pragma unused( reply, refCon )
  170.     
  171.  
  172.     return noErr;
  173.  
  174. }
  175.  
  176.  
  177. //----------------------------------------------------------------------
  178. //
  179. //    GotAEParams - make sure we got proper AE params for an Open 
  180. //                  Document from the Finder
  181. //
  182. //----------------------------------------------------------------------
  183.  
  184. OSErr GotAEParams(AppleEvent *appleEvent)
  185. {
  186.     OSErr            err;
  187.     DescType        type;
  188.     Size            size;
  189.     
  190.     err = AEGetAttributePtr(appleEvent, keyMissedKeywordAttr,
  191.                             typeWildCard, &type, nil, 0, &size);
  192.     
  193.     if (err == errAEDescNotFound)
  194.         return(noErr);
  195.     
  196.     else
  197.         if (err == noErr)
  198.             return(errAEEventNotHandled);
  199.     
  200.     return err;
  201.